package cn.gjxblog.core.captcha.sms;

import cn.gjxblog.core.captcha.BaseCaptcha;
import cn.gjxblog.core.captcha.CaptchaGenerator;
import cn.gjxblog.core.properties.SecurityProperties;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/1/17 10:30
 */
@Component("smsCaptchaGenerator")
public class DefaultSmsCaptchaGenerator implements CaptchaGenerator {

    @Resource
    private SecurityProperties securityProperties;

    @Override
    public SmsCapthcha createCaptcha() {
        String s = RandomStringUtils.randomNumeric(securityProperties.getCaptcha().getSms().getLength());
        return new SmsCapthcha(s,securityProperties.getCaptcha().getSms().getExpire());
    }
}
